﻿using HCQ2_IBLL;
using HCQ2_Model;
using HCQ2_Model.VRDD.InputDto;
using HCQ2_Model.VRDD.InputDto._0427;
using HCQ2_Model.VRDD.InputDto._0531;
using HCQ2_Model.VRDD.InputDto._0629;
using HCQ2_Model.VRDD.OutputDto._0427;
using HCQ2_Model.VRDD.OutputDto._0525;
using HCQ2_Model.VRDD.OutputDto._0629;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HCQ2_BLL
{
    public partial class DD_UserBLL: IDD_UserBLL
    {
        /// <summary>
        ///  获取我的信息
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public OutMyInfo GetMyInfo(MyBaseUser param,string user_guid)
        {
            OutMyInfo o = DBSession.IDD_UserDAL.GetMyInfo(param,user_guid);
            if(o!=null && !string.IsNullOrEmpty(o.user_img) && o.user_img.IndexOf("http")<0)
                o.user_img = o.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            return o;
        }
        /// <summary>
        /// 获取我附近的用户
        /// </summary>
        /// <param name="param">查询参数</param>
        /// <param name="gps_x">经度</param>
        /// <param name="gps_y">纬度</param>
        /// <returns>附近用户</returns>
        public List<OutNearbyUser> GetUserByMyNearby(QueryNearbyUser param, decimal gps_x, decimal gps_y)
        {
            var list = DBSession.IDD_UserDAL.GetUserByMyNearby(param, gps_x, gps_y);
            list?.ForEach(s =>
            {
                if (!string.IsNullOrEmpty(s.user_img) && s.user_img.IndexOf("http")<0)
                    s.user_img = s.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
        /// <summary>
        ///  获取度度圈用户管理列表
        /// </summary>
        /// <param name="param"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public List<OutputCircleUser> GetCircleList(InputCircleUser param, out int total)
        {
            return DBSession.IDD_UserDAL.GetCircleList(param, out total);
        }
        /// <summary>
        ///  修改用户类别
        /// </summary>
        /// <param name="user_type"></param>
        /// <param name="userid"></param>
        public void ModifyUserType(int user_type, string userid)
        {
            DBSession.IDD_UserDAL.ModifyUserType(user_type, userid);
        }

        //*************************************0629需求**************************************
        /// <summary>
        ///  获取用户的最新商品
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public OutputUserArticle GetArticleParamList(InputUserArticle param)
        {
            OutputUserArticle result = new OutputUserArticle();
            int obj = DBSession.IDD_UserDAL.GetArticleParamCount(param);
            if (obj <= 0)
                return result;
            result.storeNum = obj;
            List<ArticleList> alist = new List<ArticleList>();
            List<ArticleParam> list = DBSession.IDD_UserDAL.GetArticleParamList(param);
            list?.ForEach(s =>
            {
                ArticleList temp = new ArticleList
                {
                    file_id = s.file_id,
                    file_name = s.file_name,
                    file_note = s.file_note,
                    store_id = s.store_id,
                    store_name = s.store_name,
                    store_type = s.store_type
                };
                //缩略图
                List<T_DocBagFileRecord> photoOption = DBSession.IT_DocBagFileRecordDAL.Select(o => o.file_id == s.file_id);
                if (photoOption.Count > 0)
                    photoOption.ForEach(o => o.file_url = o.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))));
                temp.photoOption = photoOption;
                alist.Add(temp);
            });
            result.list = alist;
            return result;
        }
        /// <summary>
        ///  获取用户的最新动态
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public OutputUserDynamic GetUserDynamic(InputUserArticle param)
        {
            OutputUserDynamic result = new OutputUserDynamic();
            int count = DBSession.IDD_UserDAL.GetDynamicCount(param);
            if (count <= 0)
                return result;
            result.dyNum = count;
            List<PicList> plist = DBSession.IDD_UserDAL.GetPicList(param);
            List<PicList> list = new List<PicList>();
            plist?.ForEach(s =>
            {
                list.Add(new PicList
                {
                    id = s.id,
                    create_date = s.create_date,
                    img_name = s.img_name,
                    img_url = s.img_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")))
                });
            });
            result.list = list;
            return result;
        }
        /// <summary>
        ///  获取共同好友列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputMutualFriend> GetMutualFriend(InputMutualFriend param)
        {
            List<OutputMutualFriend> list = DBSession.IDD_UserDAL.GetMutualFriend(param);
            list?.ForEach(s => {
                if (!string.IsNullOrEmpty(s.user_img) && s.user_img.IndexOf("http")<0)
                    s.user_img = s.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
    }
}